package cn.edu.sdjzu.xg.bysj.domain;

import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Calendar;

public class JWT {
    public static String createJWT(String name, String password){
        JWTCreator.Builder builder = com.auth0.jwt.JWT.create();

        builder.withClaim("username",name);
        builder.withClaim("password",password);

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE,7);//token过期时间,7天
        String SIGN = "123456789";//秘钥

        String token = builder.withExpiresAt(calendar.getTime())//设置token过期时间
                .sign(Algorithm.HMAC512(SIGN));//使用秘钥进行加密
        return token;
    }

}
